﻿Partial Public Class ucSynchReader
    Inherits UserControl

    Public Sub New 
        InitializeComponent()
    End Sub

    Private Sub UpdateRFIDData()
        Dim recordCtr As Integer = 0
        Dim SearchCriteria As String = String.Empty

        Try
            Dim path As String = "D:\Test Projects\New\"
            Dim CriteriaPath, files, filename As String

            CriteriaPath = path.Substring(0, path.LastIndexOf("\"))

            If SearchCriteria.Length = 0 Then
                SearchCriteria = "*.txt"
            Else
                SearchCriteria = path.Substring(path.LastIndexOf("\") + 1)
            End If

            For Each files In IO.Directory.EnumerateFiles(CriteriaPath, SearchCriteria)
                Label1.Content = files
                'filename = Mid(files, localLocation.Length + 1, files.Length - localLocation.Length + 1)
                'Dim parser As New FileIO.TextFieldParser(files)
                'parser.TextFieldType = FileIO.FieldType.Delimited
                'parser.SetDelimiters(" ")
                'While Not parser.EndOfData
                '    parser.ReadFields()
                'End While
                'parser.Close()
                'parser = New FileIO.TextFieldParser(files)
                'parser.TextFieldType = FileIO.FieldType.Delimited
                'parser.SetDelimiters(" ")

                'Dim currentRow() As String
                'Dim fldCtr As Integer
                'While Not parser.EndOfData
                '    fldCtr = 1
                '    Try
                '        currentRow = parser.ReadFields()
                '        Dim currentField As String
                '        For Each currentField In currentRow
                '            If fldCtr = 2 Then
                '                Dim rfidNumber As String = Mid(currentRow(1), currentRow(1).Length - 9, 10)
                '                Dim rfidScanDate As Date = CDate(Mid(filename, 1, 4) & "/" & Mid(filename, 5, 2) & "/" & Mid(filename, 7, 2))
                '                Dim RFIDDateScanned = From RFIDTable In dbRFIDScanTable.RFIDScanHistories.Where(Function(o) o.RFIDNum = rfidNumber And o.DateScanned = rfidScanDate)
                '                If RFIDDateScanned.Count = 0 Then
                '                    Dim RFIDScannedTable As New RFIDScanHistory
                '                    With RFIDScannedTable
                '                        .DateScanned = rfidScanDate
                '                        .RFIDNum = rfidNumber
                '                    End With
                '                    dbRFIDScanTable.RFIDScanHistories.InsertOnSubmit(RFIDScannedTable)
                '                End If
                '                Dim itemsTable = From ATSItemsTable In dbRFIDScanTable.MainAssetsTables _
                '                                 Where ATSItemsTable.RFIDno = rfidNumber
                '                If itemsTable.Count > 0 Then
                '                    With itemsTable.First
                '                        .LastScanDate = rfidScanDate
                '                    End With
                '                Else
                '                    If Not listboxNotonDatabase.Items.Contains(rfidNumber) Then
                '                        listboxNotonDatabase.Items.Add(rfidNumber)
                '                        listboxNotonDatabase.Items.Refresh()
                '                    End If
                '                End If
                '                dbRFIDScanTable.SubmitChanges()

                '                'Label1.Text &= currentRow(1) & ControlChars.Lf
                '                recordCtr += 1
                '            End If
                '            fldCtr += 1
                '        Next
                '    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                '        MsgBox("Line " & ex.Message & _
                '        "is not valid and will be skipped.")
                '    End Try
                'End While
                'parser.Close()

                'FileFound += 1
                'If File.Exists(files) Then
                '    File.Move(files, Mid(files, 1, files.Length - 3) & Format(Now(), "ddMMyyhhmmss"))
                'Else
                '    File.Move(files, Mid(files, 1, files.Length - 3) & "old")
                'End If

            Next

            'imgUpdateDatabaseError.Visibility = Windows.Visibility.Hidden
            'imgUpdateDatabaseOk.Visibility = Windows.Visibility.Visible
            'PBarimgUpdateDatabase.Visibility = Windows.Visibility.Hidden

            'lblNumberofRecordsProcessed.Content = recordCtr
        Catch ex As Exception
            'MsgBox("Please check format of reader files.")
            'imgUpdateDatabaseError.Visibility = Windows.Visibility.Visible
            'imgUpdateDatabaseOk.Visibility = Windows.Visibility.Hidden
            'PBarimgUpdateDatabase.Visibility = Windows.Visibility.Hidden
            Label2.Content = ex.Message.ToString
        End Try
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        UpdateRFIDData()
    End Sub
End Class
